package com.example.cutomstarterspi.properties;

import com.example.cutomstarterspi.service.StarterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: dangwen
 * @createDate: 2021/7/6
 */
@Configuration
@ConditionalOnClass(StarterService.class)
public class StarterAutoConfigure {
    @Autowired
    private StarterServiceProperties properties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "starter.config", value = "enabled" ,havingValue = "true")
    StarterService starterService(){
        return new StarterService(properties.getConfig());
    }
}
